(function ($) {
    var nodes = [
        {name: "500个节点", id: "1", count: 500, times: 1, isParent: true},
        {name: "1000个节点", id: "2", count: 1000, times: 1, isParent: true},
        {name: "2000个节点", id: "3", count: 2000, times: 1, isParent: true}
    ];

    function ajaxGetNodes(treeNode, reloadType) {
        var zTree = hqTree.getZTreeObj();// $.fn.zTree.getZTreeObj("treeDemo");
        if (reloadType == "refresh") {
            treeNode.icon = "/lib/ztree/css/zTreeStyle/img/loading.gif";
            zTree.updateNode(treeNode);
        }
        zTree.reAsyncChildNodes(treeNode, reloadType, true);
    };

    var hqTree = new HQTree({
            id: 'treeDemo',
            nodes: nodes,
            _setting: {
                async: {url: '/tree/data/1000'},
                callback: {
                    beforeExpand: function (treeId, treeNode) {
                        // this.setting.async.url += '/' + treeNode.count;
                        console.log(treeNode);
                        if (!treeNode.isAjaxing) {
                            startTime = new Date();
                            treeNode.times = 1;
                            ajaxGetNodes(treeNode, "refresh");
                            return true;
                        } else {
                            alert("zTree 正在下载数据中，请稍后展开节点。。。");
                            return false;
                        }
                    }
                }
            }
        }
    );

    $("#btn_load").bind("click", function() {
        hqTree.init();
    })

    $("#btn_loadNode").bind("click", function() {
        $.get('/tree/data', function(data) {
            console.log(data);

        });
    })
    console.log(hqTree);

})(jQuery);